package com.chhuang.core.model;

import java.io.Serializable;

import com.sun.xml.bind.CycleRecoverable.Context;

/**
 * An interface that indicates an object is a <i>persistable entity </i>.
 * 
 * @author JackDou
 */
public interface Persistable extends Serializable {
    /**
     * Provides a common getter for the persistence layer to obtain an identity,
     * irrespective of the actual type of identity used.
     * 
     * <p>
     * Typically a subclass will delegate to a <code>public
     * SomePrimitiveWrapper getId()</code>
     * method. The necessity for the <code>getId()</code> abstract method is
     * solely because the persistence layer needs a way of obtaining the
     * identity irrespective of the actual identity implementation choice.
     * </p>
     * 
     * <p>
     * Returning <code>null</code> from this method will indicate the object
     * has never been saved. This will likely be relied on by some
     * <code>Dao</code> implementations.
     * </p>
     * 
     * @return the persistence identity of this instance
     */
    Serializable getId();
    /**
     * Provides a common setter for the persistence layer to persistent an entity
     * @param id
     */ 
     void setId(Serializable id);
    /**
     * @param object
     *            an instance of <code>Persistable</code>
     * @return <code>true</code> if <code>object</code> equals this;
     *         otherwise return <code>false</code>.
     */
    boolean equals(Object object);

    /**
     * @return hash code of the object
     */
    int hashCode();
    /**
     * @return a <code>String</code> consists of all properties
     */
    String toString();
    /**
     * 
     * @param arg0
     * @return
     */
    Object onCycleDetected(Context arg0);
}
